package com.falcon.service.impl;

import com.falcon.generator.java.controller.ControllerCodeGenerator;
import com.falcon.service.IModuleService;
import com.falcon.domain.vo.ServiceModuleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zongf
 * @since 2023-06-09
 **/
@Slf4j
@Service
public class ModuleService implements IModuleService {

    @Autowired
    private ControllerCodeGenerator generator;

    @Override
    public List<ServiceModuleVO> getServiceModuleNames() {
        String services = generator.geGenerateCodePath() ;

        File servicesDirector = new File(services);

       List<ServiceModuleVO> serviceNames = Arrays.stream(servicesDirector.listFiles())
               .filter(file -> file.isDirectory()).map(file -> file.getName())
               .map(serviceModule ->{
                   String module = serviceModule.split("-")[1];
                   return new ServiceModuleVO(serviceModule, module);
               })
               .collect(Collectors.toList());

        return serviceNames;
    }

}
